package com.taotao.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.EasyUIDataGridResult;
import com.taotao.common.pojo.EasyUITreeNode;
import com.taotao.common.utils.UniResult;
import com.taotao.pojo.TbItem;
import com.taotao.service.ItemService;

@Controller
public class ItemController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(ItemController.class);
	
	@Autowired
	private ItemService itemService;
	
	/**
	 * 根据ID查询item对象
	 * @param itemId
	 * @return
	 *
	 */
	@ResponseBody
	@RequestMapping("/item/{itemId}")
	private TbItem getItemById(@PathVariable Long itemId) {
		TbItem item = itemService.getItemById(itemId);
		return item;
	}
	/**
	 * 商品列表展示
	 * @param page
	 * @param rows
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/item/list")
	public EasyUIDataGridResult getItemList(Integer page, Integer rows) {
		EasyUIDataGridResult result = itemService.getItemList(page, rows);
		return result;
	}
	
	/**
	 * 类目展示
	 * @param page
	 * @param rows
	 * @return
	 *
	 */
	@ResponseBody
	@RequestMapping("/item/cat/list")
	public List<EasyUITreeNode> getItemCatList(@RequestParam(value="id", defaultValue="0") Long parentId) {
		List<EasyUITreeNode> list = itemService.getItemCatList(parentId);
		return list;
	}
	
	/**
	 * 保存
	 * @param item
	 * @param desc
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/item/save", method=RequestMethod.POST)
	public UniResult createItem(TbItem item, String desc) {
		UniResult result = itemService.createItem(item, desc);
		return result;
	}
	
//	@RequestMapping("/item/{itemId}")
//	public String showItemParam(@PathVariable Long itemId, Model model) {
//		String html = itemService.getItemParamHtml(itemId);
//		model.addAttribute("html", html);
//		return"itemparam";
//	}



}
